home *** CD-ROM | disk | FTP | other *** search
/ Windows CE - The Ultimate Companion / ROMMAN_CE.iso / Files / Clocks & Timers / Egg Timer / EggTimer Source / Timer.cpp < prev    next >
C/C++ Source or Header  |  1997-01-21  |  7KB  |  275 lines

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <commctrl.h>
  4. extern "C" {
  5. #include <notify.h>
  6. }
  7. #include <tchar.h>
  8. //#include <stdlib.h>
  9. extern "C" wchar_t * _itow( int value, wchar_t *string, int radix );
  10.  
  11. WCHAR szAppName[80];
  12. WCHAR szTitle[80]; 
  13. WCHAR szCurrentDirectory[80]=L"\\";
  14. WCHAR szQualifiedName[160]=L"\\timer.exe";
  15.  
  16. // Emulation size window | resolution of Pegasus machine
  17. const int WINDOW_WIDTH = 480;   
  18. const int WINDOW_HEIGHT = 214; 
  19. const int PATH_MAX = 255;
  20.  
  21. const int cbWidth = 50;
  22. const int cbWidth2 = 76;
  23. const int cbID = 101;
  24. const int cbID2 = 102;
  25.  
  26.  // Height of caption bar
  27. int nCaptionSize  = GetSystemMetrics( SM_CYCAPTION );  
  28.  
  29.  // Width and Height of Client Area
  30. RECT rc;
  31. int CLIENT_WIDTH;         
  32. int CLIENT_HEIGHT;
  33.  
  34. int iCount=0;
  35. int i = 0;
  36. int units = 1;
  37. int num = 1;
  38. HANDLE hn=NULL;
  39. HWND hwndCB,hwndCombo,hwndCombo2;
  40. HDC hDC;
  41. HINSTANCE hInst=NULL;
  42. SYSTEMTIME tm;
  43. TCHAR pwszSound[PATH_MAX]=L"ALARM1.WAV";
  44. PEG_USER_NOTIFICATION un = {
  45.     PUN_DIALOG | PUN_LED | PUN_SOUND | PUN_REPEAT,
  46.     L"Egg Timer",
  47.     L"It's time!",
  48.     pwszSound,
  49.     PATH_MAX*sizeof(TCHAR),
  50.     0};
  51.  
  52. LRESULT DoCommand( HWND hWnd, WORD id)
  53. {
  54.     switch (id) {
  55.     case IDOK:
  56.         PegGetUserNotificationPreferences(hWnd,&un);
  57.         GetLocalTime(&tm);
  58.         num=SendMessage(hwndCombo,CB_GETCURSEL,0,0);
  59.         units=SendMessage(hwndCombo2,CB_GETCURSEL,0,0);
  60.         switch(units) {
  61.         case 0:
  62.             tm.wSecond += num;
  63.             break;
  64.         case 1:
  65.             tm.wMinute += num;
  66.             break;
  67.         case 2:
  68.             tm.wHour += num;
  69.             break;
  70.         default:
  71.             tm.wMinute += num;
  72.             break;
  73.         }
  74.         while(tm.wSecond>=60) {
  75.             tm.wSecond -= 60;
  76.             tm.wMinute++;
  77.         }
  78.         while(tm.wMinute>=60) {
  79.             tm.wMinute -= 60;
  80.             tm.wHour++;
  81.         }
  82.         while(tm.wHour>=24) {
  83.             tm.wHour -= 24;
  84.             tm.wDay++;
  85.         }
  86.  
  87.         hn=PegSetUserNotification(0,szQualifiedName,&tm,&un);
  88.         if(hn==0) {
  89.             MessageBox(hWnd,L"PegSetUserNotification failed",L"Debug",MB_OK);
  90.         }
  91.         else {
  92.             PegHandleAppNotifications(szQualifiedName);
  93.             hDC=GetDC(hWnd);
  94.             ExtTextOut(hDC,4,nCaptionSize+2,ETO_OPAQUE,&rc,L"Timer set!",10,NULL);
  95.             ReleaseDC(hWnd,hDC);
  96.         }
  97.         break;
  98.  
  99.     case cbID:
  100.     case cbID2:
  101. //        MessageBox(hWnd,L"ComboBox message seen",L"Debug",MB_OK);
  102.         break;
  103.  
  104.     default:
  105.         break;
  106.     }
  107.     return 0;
  108. }
  109.  
  110. LRESULT CALLBACK WndProc (    HWND hWnd,
  111.                             UINT message,
  112.                             WPARAM uParam,
  113.                             LPARAM lParam )
  114. {
  115.     TCHAR tz[4];
  116.     HDC hdc;
  117.     PAINTSTRUCT ps;
  118.  
  119.     switch (message) {
  120.     case WM_COMMAND:
  121.           DoCommand(hWnd, GET_WM_COMMAND_ID(uParam, lParam));
  122.           break;
  123.  
  124.     case WM_CREATE:
  125.         hwndCB = CommandBar_Create(hInst, hWnd, 1);
  126.         hwndCombo = CommandBar_InsertComboBox(hwndCB,hInst,cbWidth,CBS_DROPDOWNLIST|WS_VSCROLL,cbID,0);
  127.         hwndCombo2= CommandBar_InsertComboBox(hwndCB,hInst,cbWidth2,CBS_DROPDOWNLIST|WS_VSCROLL,cbID2,1);
  128.         CommandBar_AddAdornments(hwndCB, CMDBAR_OK, 0);
  129.         for(i=0;i<100;i++) {
  130.             _itow(i,tz,10);
  131.             SendMessage(hwndCombo,CB_ADDSTRING,0,(long)tz);
  132.         }
  133.         SendMessage(hwndCombo,CB_SETCURSEL,3,0); //default to 3
  134.  
  135.         SendMessage(hwndCombo2,CB_ADDSTRING,0,(long)TEXT("seconds"));
  136.         SendMessage(hwndCombo2,CB_ADDSTRING,0,(long)TEXT("minutes"));
  137.         SendMessage(hwndCombo2,CB_ADDSTRING,0,(long)TEXT("hours"));
  138.         SendMessage(hwndCombo2,CB_SETCURSEL,1,0); //default to minutes
  139.  
  140.         rc.top=nCaptionSize;
  141.         break;
  142.  
  143.     case WM_PAINT:
  144.         hdc = BeginPaint(hWnd, &ps);
  145.         EndPaint(hWnd, &ps);
  146.         break;
  147.  
  148.     case WM_DESTROY:
  149.         PostQuitMessage(0);
  150.         break;
  151.  
  152.     default:
  153.         return (DefWindowProc(hWnd, message, uParam, lParam));
  154.     }
  155.  
  156.     return (0);
  157. }
  158. /***************************************************************************
  159.  
  160.         BOOL InitApplication ( HINSTANCE hInstance )
  161.  
  162. ****************************************************************************/
  163. BOOL InitApplication ( HINSTANCE hInstance )
  164. {
  165.     WNDCLASSW  wc;
  166.     BOOL f;
  167.  
  168.     wc.style =  0 ;                     
  169.     wc.lpfnWndProc = (WNDPROC) WndProc;
  170.     wc.cbClsExtra = 0;
  171.     wc.cbWndExtra = 0;
  172.     wc.hInstance = hInstance;
  173.     wc.hIcon = NULL;                              
  174.     wc.hCursor = NULL;                                           
  175.     wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  176.     wc.lpszMenuName = NULL;
  177.     wc.lpszClassName = szAppName;
  178.  
  179.     f = (RegisterClass(&wc));
  180.     return f;
  181. }
  182. /*************************************************************************************
  183.  
  184.         BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
  185.  
  186.   ************************************************************************************/
  187.  
  188. BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
  189. {
  190.     HWND hWnd;
  191.     hInst = hInstance;
  192.  
  193.                                    // Use default window settings
  194. #ifdef TARGET_NT
  195.      hWnd = CreateWindow(szAppName,szTitle,WS_POPUP,
  196.                          0,0,CW_USEDEFAULT,CW_USEDEFAULT,
  197.                          NULL, NULL, hInstance, NULL);
  198. #else
  199.      hWnd = CreateWindow(szAppName,szTitle,WS_VISIBLE,
  200.                          0,0,CW_USEDEFAULT,CW_USEDEFAULT,
  201.                          NULL, NULL, hInstance, NULL);
  202. #endif
  203.  
  204.  
  205.      if ( hWnd == 0 )    // Check CreateWindow return values for validity
  206.         { return (FALSE); }
  207.      if (IsWindow(hWnd) != TRUE) 
  208.         { return (FALSE); }
  209.  
  210.     GetClientRect(hWnd, &rc);
  211.     CLIENT_WIDTH = rc.right;
  212.     CLIENT_HEIGHT = rc.bottom;
  213.     ShowWindow(hWnd, SW_SHOW);
  214.     UpdateWindow(hWnd);
  215.  
  216. /*    GetCurrentDirectory(80,szCurrentDirectory);
  217.     lstrcpy(szQualifiedName,szCurrentDirectory);
  218.     lstrcat(szQualifiedName,szAppName);
  219.     lstrcat(szQualifiedName,L".exe");
  220. */
  221.     PegHandleAppNotifications(szQualifiedName);
  222.  
  223.     return(TRUE);                  // Window handle hWnd is valid   
  224. }
  225. /***************************************************************************
  226.  
  227.         int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  228.                                 LPWSTR lpCmdLine ,UINT nCmdShow )
  229.  
  230.   **************************************************************************/
  231.  
  232. int WINAPI WinMain ( HINSTANCE hInstance,
  233.                      HINSTANCE hPrevInstance,
  234.                      LPWSTR lpCmdLine,     
  235.                      int nCmdShow )
  236.  
  237. {
  238.     MSG msg;
  239.     HWND hwndPrev;
  240.  
  241.     //Load strings
  242.     LoadString(hInstance,1,szAppName,
  243.                sizeof(szAppName)/sizeof(TCHAR));
  244.     LoadString(hInstance, 2,szTitle,
  245.                sizeof(szTitle)/sizeof(TCHAR));
  246.  
  247.    
  248.     if ( lstrlen(lpCmdLine) ) {
  249.         PegHandleAppNotifications(szQualifiedName);
  250.         hwndPrev=FindWindow(szAppName,szTitle);
  251.         if(hwndPrev) {
  252.             SetFocus(hwndPrev);
  253.             return (FALSE);
  254.         }
  255.     }
  256.  
  257.     if ( hPrevInstance == 0 )
  258.     {
  259.         if ( InitApplication(hInstance) == FALSE ) 
  260.             { return(FALSE);}
  261.     }
  262.  
  263.     if ( InitInstance(hInstance, nCmdShow) == FALSE ) 
  264.         { return(FALSE);}
  265.  
  266.  
  267.     while ( GetMessage(&msg, NULL, 0, 0) == TRUE ) 
  268.     {
  269.         
  270.         DispatchMessage(&msg);
  271.     }
  272.  
  273.     return(msg.wParam);
  274. }
  275.